/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.jiujiudevice.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.jiujiudevice.entity.JiuConsumeConfig;
import com.boxin.ims.modules.jiujiudevice.dao.JiuConsumeConfigDao;

/**
 * 消费配置Service
 * @author sxh
 * @version 2018-11-14
 */
@Component
@Transactional(readOnly = true)
public class JiuConsumeConfigService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(JiuConsumeConfigService.class);
	
	@Autowired
	private JiuConsumeConfigDao jiuConsumeConfigDao;
	
	public JiuConsumeConfig get(Long id) {
		return jiuConsumeConfigDao.findOne(id);
	}
	
	public Page<JiuConsumeConfig> find(Page<JiuConsumeConfig> page, JiuConsumeConfig jiuConsumeConfig) {
		DetachedCriteria dc = jiuConsumeConfigDao.createDetachedCriteria();
		if (jiuConsumeConfig.getUser()!=null && jiuConsumeConfig.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", jiuConsumeConfig.getUser().getId()));
		}
		if (StringUtils.isNotEmpty(jiuConsumeConfig.getName())){
			dc.add(Restrictions.like("name", "%"+jiuConsumeConfig.getName()+"%"));
		}
		dc.addOrder(Order.desc("id"));
		return jiuConsumeConfigDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(JiuConsumeConfig jiuConsumeConfig) {
		jiuConsumeConfigDao.save(jiuConsumeConfig);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		jiuConsumeConfigDao.deleteById(id);
	}
	
	
	/***
	 * 
	 * @function: <p>查询所有的其他消费配置 </p>
	 * @return
	 */
	public List<JiuConsumeConfig> findAll() {
		DetachedCriteria dc = jiuConsumeConfigDao.createDetachedCriteria();
		return jiuConsumeConfigDao.find(dc);
	}
	
	
}
